home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 37
/
Aminet 37 (2000)(Schatztruhe)[!][Jun 2000].iso
/
Aminet
/
dev
/
misc
/
AWNP_2-39.lha
/
AWNP
/
AWNP-Docs
/
Tutorials
/
tutorial5.rx
< prev
next >
Wrap
Text File
|
2000-02-11
|
10KB
|
386 lines
/*Tutorial 5 for AWNPipe*/
if show('P','TUTORIAL5') then do
address TUTORIAL5 'front'
exit
end
/* keep env setting compatable to demo 4*/
envname='GUITutorial4'
delaybub=0
call setdefaults()
call buildgui()
topipe('id 'savegad' dis 1 ref')
/*main loop*/
do while ~eof(ca)
call topipe('tick 50')
in= readln(ca)
parse var in in1 in2 in3 in4 in5 .
/*handle help display delay*/
if delaybub>0 then do
delaybub=delaybub-1
/* if we reach zero display the help bubble*/
if delaybub=0 then do
bubleon=newbub
call topipe('bubble top 'bubx 'left 'buby 'gt "'help.newbub'"')
end
end
if (in1='help' & helpon~=0 ) then call bubble(in2)
/*close help bubble if active state of window changes*/
if in1='active' then call bubble(0)
if in1='gadget' then call gadget()
if in1='menu' then call menu()
if in1='close' then call windowclosed()
if in1='iconify' then call iconify()
if in1='app' then call app()
if in1='arexx' then call rxhst()
end
/*end of main loop*/
exit
gadget:
if in2=agegad then age=in3
if in2=sexgad then sex=in3
if in2=knogad then knowledge=in3
if in2=basgad then basic=in3
if in2=aregad then arexx=in3
if in2=cgad then c=in3
if in2=asmgad then asm=in3
/* the return from a string gadget is parsed differently since it can be more
then 1 word. */
if in2=namegad then do
parse var in . . in3
/*strip it since arexx parsing adds the leading space to the last string
assignment*/
name=strip(in3)
if name='' then call topipe('id 'savegad' dis 1 ref')
else call topipe('id 'savegad' dis 0 ref')
end
if in2=dongad then do
showtx(0, 'Normal exit *nname' name '*nage' age '*nsex' sex '*nknowledge' knowledge '*nbasic' basic 'arexx' arexx 'c' c 'asm' asm)
exit
end
if in2=resgad then call resetform()
if in2=savegad then call saveform()
if in2=loadgad then call loadform()
if in2=cangad then do
showtx(300,'user canceled')
exit
end
return
windowclosed:
showtx(300,'User aborted with CTRL BackSlash or closed window.')
exit
return
menu:
if in2=0 then do
if in3=0 then do
if in4=0 then call setenvarc()
if in4=1 then call unsetenvarc()
end
if in3=1 then do
helpon=in5
if helpon=0 then call bubble(0)
end
if in3=3 then showtx(500,' Tutorial 4 for AWNP *n by William Parker')
end
if in2=1 then do
if in3=0 then do
showtx(0, 'name' name '*nage' age '*nsex' sex '*nknowledge' knowledge '*nbasic' basic 'arexx' arexx 'c' c 'asm' asm)
end
if in3=1 then do
if in4=0 then showtx(0, 'name' name '*nage' age '*nsex' sex)
if in4=1 then showtx(0, 'knowledge' knowledge '*nbasic' basic 'arexx' arexx 'c' c 'asm' asm)
end
end
return
setdefaults:
name=''
age=30
sex=0
knowledge=0
basic=0
c=0
asm=0
arexx=0
return
buildgui:
/* get our window size and position */
call getenv()
/* Open pipe 'tut2' with GUI creation option '/xc' */
call open(ca,"awnpipe:tut4/xc")
/* define the window */
/* The first line oF every GUI is the window definition. The window is titled
"Tutorial 2" and its elements will be laid out verticaly (v). It has a
closegadget (cg) , depthgadget (dg) , and dragbar (db). It will have spaces
inbetween its gadgets (si). It will open on the topleft (tl) of the screen
becoming active (a) when opened. The window can be icoified (ig) and modified
(m). It is an app window (app) . It can be sized (SG) but not verticaly (fh)*/
call topipe(' "Tutorial 5" v cg dg db si a help state ig sg fh m app ii "tutorial4.rx" 'windowdef)
/* define the gadgets*/
call topipe(' layout b 0 v')
/* Labels are used to tell the user what information to enter in each gadget.
These labels are unatached (ua) when they are defined so don't go directly
into the GUI. Instead they are attached to the following gadget by the
childlabel (chl) keyword. */
call topipe(' label gt "Name: " ua')
namegad=topipe('string lj chl')
help.namegad='Enter a name here. This feild must be valid*n before you can save the information.'
call topipe(' label gt "Age: " ua')
agegad=topipe('integer chl minn 5 maxn 115 arrows defn 30 weiw 0')
help.agegad='Enter an age between 5 and 115'
call topipe(' label gt "Sex: " ua')
sexgad=topipe('radiobutton rl "Male|Female" chl')
help.sexgad='You may only choose one sex.'
call topipe(' label gt "Knowledge: " ua')
knogad=topipe('chooser pu cl "Novice|Average|Good|Expert" chl')
help.knogad='Enter your programming knowledge level.'
call topipe(' label gt "Language(s): " ua')
call topipe(' layout b 0 chl')
basgad=topipe('checkbox gt "Basic " chl')
help.basgad='Select if you program in Basic.'
aregad=topipe('checkbox gt "Arexx " chl')
help.aregad='Select if you program in Arexx.'
cgad=topipe('checkbox gt "C " chl')
help.cgad='Select if you program in C.'
asmgad=topipe('checkbox gt "ASM " chl')
call topipe(' le')
help.asmgad='Select if you program in Assembler.'
call topipe(' le')
call topipe(' layout si so')
savegad= topipe('button gt "Save" ')
help.savegad='Save data to a file.*n(You must enter a name first)'
loadgad= topipe('button gt "Load" ')
help.loadgad='Read a data file.'
resgad= topipe('button gt "Reset Form" ')
help.resgad='Reset the form to defaults.'
dongad= topipe('button gt "Done" c')
help.dongad='Display data and quit the demo.'
cangad= topipe('button gt "Cancel" c')
help.cangad='Quit the demo without displaying the data.'
call topipe(' le')
call topipe(' menu gt "Project|Window|$@SSnapshot|$@UUnSnapshot|^&Bubble Help|-|About"')
call topipe(' menu gt "Data|@AShow all data|Show part|$@PPersonal|$@SSkill"')
call topipe(' arexx gt "TUTORIAL5|age|sex|knowledge|front|quit"')
getfilegad=topipe('getfile gt "Select Information File" fn "t:" ua pat "#?.tut3"')
/*open the GUI window*/
call topipe("open")
return
topipe:
/* this routine does error checking on lines written to pipe.*/
/*get line to output*/
parse arg out
/* write to the pipe*/
call writeln(ca,out)
/*get responce and parse it.*/
res=readln(ca)
parse var res res1 res2 .
/* if all is ok return the second part of the responce (usualy the GID)*/
if res1='ok' then return(res2)
/* something went wrong, we notify the user then exit */
/*show problem line and responce (reponce may be just a blank line)*/
say 'error from: 'out
say ' responce: ' res
exit
resetform:
call topipe('id 'agegad' defn 30 ref')
call topipe('id 'sexgad' s 0 ref')
call topipe('id 'knogad' s 0 ref ')
call topipe('id 'basgad' s 0 ref')
call topipe('id 'aregad' s 0 ref')
call topipe('id 'cgad' s 0 ref ')
call topipe('id 'asmgad' s 0 ref')
call topipe('id 'namegad' gt "" ref')
topipe('id 'savegad' dis 1 ref')
call setdefaults()
return
saveform:
call open(form,'t:'name'.tut3','W')
call writech(form,age sex knowledge basic arexx c asm name)
call close(form)
return
loadform:
call writeln(ca,'id 'getfilegad' fn "t:" s 1')
res=readln(ca);
parse var res res1 '"' filename '"'
loadapp:
if res1=0 then return
call open(form,filename,'R')
formin=readch(form,1000)
parse var formin age sex knowledge basic arexx c asm name
name=substr(name,2)
call close(form)
/*uniconify in case its needed*/
update:
call topipe('id 0 s 64')
call topipe('id 'agegad' defn 'age' ref')
call topipe('id 'sexgad' s 'sex' ref')
call topipe('id 'knogad' s 'knowledge' ref ')
call topipe('id 'basgad' s 'basic' ref')
call topipe('id 'aregad' s 'arexx' ref')
call topipe('id 'cgad' s 'c' ref ')
call topipe('id 'asmgad' s 'asm' ref')
call topipe('id 'namegad' gt "'name'" ref')
if name='' then call topipe('id 'savegad' dis 1 ref')
else call topipe('id 'savegad' dis 0 ref')
return
app:
parse var in . in2
filename=strip(in2)
if (right(filename,5)='.tut3') then do
res1=1
call loadapp()
end
return
/* send a modify command to iconify/uniconify window and remember the current
state of the window*/
iconify:
iconified=in2
if in2=1 then call topipe('id 0 s 32')
else call topipe('id 0 s 64')
return
showtx:
call open(ptx,'awnpipe:tut3txt/xc')
call writeln(ptx,'db dg "Tutorial 4" q cg cm m a so si ')
call writeln(ptx,'label lj gt "'arg(2)'"')
call writeln(ptx,'open')
if arg(1)~=0 then call writeln(ptx,'tick 'arg(1))
else call writeln(ptx,'m')
call close(ptx)
return(0)
setenv:
call writeln(ca,'id 0 read')
windowr=readln(ca)
if open(env,'env:'envname,'W') then do
call writech(env,windowr)
close(env)
end
return(0)
setenvarc:
call setenv()
address command 'copy env:'envname 'envarc:'envname' >nil:'
return
unsetenvarc:
if exists('envarc:'envname) then delete('envarc:'envname)
if exists('env:'envname) then delete('env:'envname)
return
getenv:
windowdef='tl'
if(open(env,'env:'envname,'R')) then do
windowt=readln(env)
parse var windowt wl wt ww wh .
if (datatype(wt,N) &datatype(wl,N) &datatype(ww,N) & datatype(wh,N) ) then
windowdef= 'top' wt 'left' wl 'width' ww 'height' 1
close(env)
end
return
bubble:
/* get help gadget number*/
newbub=arg(1)
if newbub=-1 then newbub=0
/* return if it has not changed*/
if (bubbleon=newbub) then return()
/* close old bubble if we have one*/
if bubbleon~=0 then call topipe('bubble')
/* if its not a valid gadget kill count down to display*/
if newbub=0 then delaybub=0
/*else remeber mouse position and start new countdown*/
else do
bubx=in3
buby=in4
delaybub=3
end
return
rxhst:
/*read the external command from the pipe*/
rxcmd=readch(ca,in3)
if in2>4 then call topipe("rc 10")
if in2=3 then do
call topipe('rc 0 result "Window brought to front"')
call topipe('id 0 s 66')
end
if in2=4 then do
call topipe('rc 0 result "tutrial 5 exiting"')
exit
end
parse var rxcmd rx1 rx2 .
if rx2='' then do
if in2=0 then call topipe('rc 0 result "'age'"')
if in2=1 then call topipe('rc 0 result "'sex'"')
if in2=2 then call topipe('rc 0 result "'knowledge'"')
end
else do
if in2=0 then age=rx2
if in2=1 then sex=rx2
if in2=2 then knowledge=rx2
call topipe('rc 0')
call update()
end
return